import { Message } from "element-ui";
import language from "./Language";
const t = language.local;
// 为了实现Class的私有属性
const showMessage = Symbol("showMessage");
/**
 *  重写ElementUI的Message
 *  single默认值true，因为项目需求，默认只弹出一个，可以根据实际需要设置
 */
class DonMessage {

  success (options, single = true) {
    this[showMessage]("success", options, single);
  }
  warning (options, single = true) {
    this[showMessage]("warning", options, single);
  }
  info (options, single = true) {
    console.log(options);
    this[showMessage]("info", options, single);
  }
  error (options, single = true) {
    this[showMessage]("error", options, single);
  }

  [showMessage] (type, options, single) {
    options = t(options);
    if (single) {
      // 判断是否已存在Message
      if (document.getElementsByClassName("el-message--error").length === 0) {
        Message[type](options);
      }
    } else {
      Message[type](options);
    }
  }
  static install (Vue) {
    Vue.prototype.$message = new DonMessage();
  }
}
export default DonMessage;
